package com.xmx.productcenter.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import com.xmx.productcenter.entity.GoodsSpecificationEntity;
import com.xmx.productcenter.service.GoodsSpecificationService;
import com.xmx.common.utils.PageUtils;
import com.xmx.common.utils.R;
import io.swagger.annotations.Api;


/**
 * 商品规格表
 *
 * @author fbb
 * @email boyinbing@126.com
 * @date 2021-08-11 01:24:54
 */
@Api(tags = "GoodsSpecificationController", description = "商品规格表服务")
@RestController
@RequestMapping("productcenter/goodsspecification")
public class GoodsSpecificationController {
    @Autowired
    private GoodsSpecificationService goodsSpecificationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("productcenter:goodsspecification:list")
    @ApiOperation("获取所有商品规格表信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsSpecificationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("productcenter:goodsspecification:info")
    @ApiOperation("获取指定id的商品规格表详情")
    public R info(@PathVariable("id") Integer id){
		GoodsSpecificationEntity goodsSpecification = goodsSpecificationService.getById(id);

        return R.ok().put("goodsSpecification", goodsSpecification);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("添加商品规格表信息")
    //@RequiresPermissions("productcenter:goodsspecification:save")
    public R save(@RequestBody GoodsSpecificationEntity goodsSpecification){
		goodsSpecificationService.save(goodsSpecification);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation("更新指定id商品规格表信息")
    //@RequiresPermissions("productcenter:goodsspecification:update")
    public R update(@RequestBody GoodsSpecificationEntity goodsSpecification){
		goodsSpecificationService.updateById(goodsSpecification);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除指定id商品规格表信息")
    //@RequiresPermissions("productcenter:goodsspecification:delete")
    public R delete(@RequestBody Integer[] ids){
		goodsSpecificationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/infos/{goods_id}")
    public R getBygoodsid(@PathVariable("goods_id") Integer id){
        QueryWrapper<GoodsSpecificationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id",id);
        List<GoodsSpecificationEntity> list = goodsSpecificationService.list(wrapper);
        return R.ok().put("page", list);
     }
}
